package com.yimu.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yimu.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.yimu.system.domain.Devices;
import com.yimu.system.mapper.SignalStrengthLogMapper;
import com.yimu.system.domain.SignalStrengthLog;
import com.yimu.system.service.ISignalStrengthLogService;
import com.yimu.common.core.text.Convert;

/**
 * 设备信号强度日志Service业务层处理
 * 
 * @author Christine
 * @date 2020-08-26
 */
@Service
public class SignalStrengthLogServiceImpl implements ISignalStrengthLogService 
{
    @Autowired
    private SignalStrengthLogMapper signalStrengthLogMapper;

    /**
     * 查询设备信号强度日志
     * 
     * @param Id 设备信号强度日志ID
     * @return 设备信号强度日志
     */
    @Override
    public SignalStrengthLog selectSignalStrengthLogById(Long Id)
    {
        return signalStrengthLogMapper.selectSignalStrengthLogById(Id);
    }

    /**
     * 查询设备信号强度日志列表
     * 
     * @param signalStrengthLog 设备信号强度日志
     * @return 设备信号强度日志
     */
    @Override
    public List<SignalStrengthLog> selectSignalStrengthLogList(SignalStrengthLog signalStrengthLog)
    {
        return signalStrengthLogMapper.selectSignalStrengthLogList(signalStrengthLog);
    }

    /**
     * 新增设备信号强度日志
     * 
     * @param signalStrengthLog 设备信号强度日志
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSignalStrengthLog(SignalStrengthLog signalStrengthLog)
    {
        int rows = signalStrengthLogMapper.insertSignalStrengthLog(signalStrengthLog);
        insertDevices(signalStrengthLog);
        return rows;
    }

    /**
     * 修改设备信号强度日志
     * 
     * @param signalStrengthLog 设备信号强度日志
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSignalStrengthLog(SignalStrengthLog signalStrengthLog)
    {
        signalStrengthLogMapper.deleteDevicesByDeviceNum(signalStrengthLog.getId());
        insertDevices(signalStrengthLog);
        return signalStrengthLogMapper.updateSignalStrengthLog(signalStrengthLog);
    }

    /**
     * 删除设备信号强度日志对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSignalStrengthLogByIds(String ids)
    {
        signalStrengthLogMapper.deleteDevicesByDeviceNums(Convert.toStrArray(ids));
        return signalStrengthLogMapper.deleteSignalStrengthLogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除设备信号强度日志信息
     * 
     * @param Id 设备信号强度日志ID
     * @return 结果
     */
    @Override
    public int deleteSignalStrengthLogById(Long Id)
    {
        signalStrengthLogMapper.deleteDevicesByDeviceNum(Id);
        return signalStrengthLogMapper.deleteSignalStrengthLogById(Id);
    }

    /**
     * 新增终端列表信息
     * 
     * @param signalStrengthLog 设备信号强度日志对象
     */
    public void insertDevices(SignalStrengthLog signalStrengthLog)
    {
        List<Devices> devicesList = signalStrengthLog.getDevicesList();
        Long Id = signalStrengthLog.getId();
        if (StringUtils.isNotNull(devicesList))
        {
            List<Devices> list = new ArrayList<Devices>();
            for (Devices devices : devicesList)
            {
                devices.setId(Id);
                list.add(devices);
            }
            if (list.size() > 0)
            {
                signalStrengthLogMapper.batchDevices(list);
            }
        }
    }
}
